export const getStr = (str, max_len) =>  {
    var str_min = '';
    if (str != null) {
        var len = 0;

        for (var i = 0; i < str.length; i++) {
            var c = str.charCodeAt(i);

            if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
                len++;
            }
            //双字节加2
            else {
                len += 2;
            }

            if (len <= max_len) {
                str_min += str.substring(i, i + 1);
            } else {
                str_min += '';
            }
        }
        if (len > max_len) {
            str_min += '...'
        }
    }

    return str_min;
};
// 防抖函数   多次调用执行一次
export const debounce = (fn, delay = 500) => {
    let timer = null;

    return function () {
        if (timer) {
            clearTimeout(timer)
        }
        timer = setTimeout(() => {
            fn.apply(this, arguments)
            timer = null
        }, delay)
    }
}